package com.xiaobaibai.units;

import com.qiniu.common.QiniuException;
import com.qiniu.http.Response;
import com.qiniu.sms.SmsManager;
import com.qiniu.util.Auth;
import com.xiaobaibai.common.PayCommon;
import com.xiaobaibai.common.QiniuCommon;
import com.xiaobaibai.common.UserCommon;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

@Slf4j
@Component
public class SmsUnit implements ApplicationRunner {

    @Override
    public void run(ApplicationArguments args) {
        auth = Auth.create(QiniuCommon.accessKey, QiniuCommon.secretKey);
    }

    // 设置需要操作的账号的AK和SK
    private static Auth auth ;

    //老板:库存不足提醒
    public static void insufficientStock(Integer productId,String productName){
        SmsManager smsManager = new SmsManager(auth);
        try {
            Map<String, String> map = new HashMap<String, String>();
            Response resp = smsManager.sendMessage(
                    "0",
                    new String[] {PayCommon.adminPhone},
                    map);
            log.info(resp.bodyString());
        } catch (QiniuException e) {
            e.printStackTrace();
        }
    }

    //老板:订单提醒(新,取,退)
    public static void sendOrderStatus(String content){//里面就是内容
        SmsManager smsManager = new SmsManager(auth);
        try {
            Map<String, String> map = new HashMap<String, String>();
            Response resp = smsManager.sendMessage(
                    "1",
                    new String[] {PayCommon.adminPhone},
                    map);
            log.info(resp.bodyString());
        } catch (QiniuException e) {
            e.printStackTrace();
        }
    }

    //顾客:下单提醒(收货地址的手机号)
    public static void sendCreateOkOrder(String phone,String orderId,String productNames,
                                 String address,String status,String marks){
        SmsManager smsManager = new SmsManager(auth);
        try {
            Map<String, String> map = new HashMap<String, String>();
            Response resp = smsManager.sendMessage(
                    "2",
                    new String[] {phone},
                    map);
            log.info(resp.bodyString());
        } catch (QiniuException e) {
            e.printStackTrace();
        }
    }

    //顾客:确认收货提醒(收货地址的手机号)
    public static void sendConfirmOrder(String phone,String orderId,String status,String marks){
        SmsManager smsManager = new SmsManager(auth);
        try {
            Map<String, String> map = new HashMap<String, String>();
            Response resp = smsManager.sendMessage(
                    "3",
                    new String[] {phone},
                    map);
            log.info(resp.bodyString());
        } catch (QiniuException e) {
            e.printStackTrace();
        }
    }

    //顾客:取消订单的结果通知
    public static void sendCancelResult(String phone,String orderId,String result,//已取消/未取消
                                         String marks){
        SmsManager smsManager = new SmsManager(auth);
        try {
            Map<String, String> map = new HashMap<String, String>();
            Response resp = smsManager.sendMessage(
                    "4",
                    new String[] {phone},
                    map);
            log.info(resp.bodyString());
        } catch (QiniuException e) {
            e.printStackTrace();
        }
    }

    //顾客:拒绝退款的结果通知
    public static void sendNoReturn(String phone,String orderId,
                                        String marks){
        SmsManager smsManager = new SmsManager(auth);
        try {
            Map<String, String> map = new HashMap<String, String>();
            Response resp = smsManager.sendMessage(
                    "5",
                    new String[] {phone},
                    map);
            log.info(resp.bodyString());
        } catch (QiniuException e) {
            e.printStackTrace();
        }
    }

    //顾客:同意退款的结果通知
    public static void sendAgreeReturn(String phone,String orderId,String amount,
                                    String marks){
        SmsManager smsManager = new SmsManager(auth);
        try {
            Map<String, String> map = new HashMap<String, String>();
            Response resp = smsManager.sendMessage(
                    "6",
                    new String[] {phone},
                    map);
            log.info(resp.bodyString());
        } catch (QiniuException e) {
            e.printStackTrace();
        }
    }

}
